﻿using NLog;
using NLog.Config;
using NLog.Targets;

namespace SsoaFramework.Core.Other
{
    static class Log
    {
        public static Logger Instance;

        static Log()
        {
            LoggingConfiguration config = new LoggingConfiguration();

            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);

            consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${message}";

            LoggingRule rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget);
            config.LoggingRules.Add(rule1);

            var target = new LogReceiverWebServiceTarget()
            {
                EndpointAddress = "http://localhost:9900/",
                IncludeEventProperties = true,
                ClientId = "${guid:cached=true}"
            };
            config.AddTarget("receiver", target);
            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, target));
            
            LogManager.Configuration = config;

            Instance = LogManager.GetLogger("ESB");
        }
    }
}
